home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / misc / emu / QDOS2.lha / QLsource / src / sub.asm < prev   
Assembly Source File  |  1996-02-06  |  7KB  |  384 lines

  1. BPLCON1 EQU    $DFF102
  2. INTENA    EQU    $DFF09A
  3. INTREQ    EQU    $DFF09C
  4. DMACON    EQU    $DFF096
  5. DMACONR EQU    $DFF002
  6. BLACK     EQU      $0000
  7. RED     EQU      $0F00
  8. GREEN     EQU      $00F0
  9. BLUE     EQU      $000F
  10. WHITE     EQU      $0FFF
  11. YELLOW     EQU      $0FF0
  12. CYAN     EQU      $00FF
  13. MAGENTA  EQU      $0F0F
  14. COLOR00  EQU      $DFF180
  15.  
  16. _LVOSuperState    EQU    -150
  17. AttnFlags    EQU    296
  18. CACRF_EnableI    EQU    0
  19. CACRF_EnableD    EQU    8
  20.  
  21.     section text    code
  22.  
  23. ; m/c subroutine to do all the dirty work for L_QDOS.
  24. ; the following is passed on the stack:
  25. ;
  26. ; a0 $04(A7) sub_dst      : safe address for the subroutine that moves things about
  27. ; a1 $08(A7) ql_lomem      : lomem for QDOS
  28. ; a2 $0C(A7) ql_himem      : himem for QDOS
  29. ; a3 $10(A7) rom_dst      : address where to move the ROM images
  30. ; a4 $14(A7) qp       : address where the ROM images are currently loaded
  31. ; d0 $1C(A7) rom[0].rlen  : length of QDOS
  32. ; d1 $20(A7) rom_len      : sum of the lengths of the ROM images
  33. ; d2 $24(A7) rom[1].rlen  : length of MAIN ROM
  34. ; d3 $28(A7) ql_ssp      : SSP for QDOS
  35. ; d4 $2C(A7) qldate      : date for QDOS
  36.  
  37. _sub:
  38.     movea.l $4,a6
  39.     jsr    _LVOSuperState(a6) ; enter supervisor mode
  40.     move.l    d0,d7
  41.  
  42.     or    #$0700,sr    ; disable all interrupts
  43.  
  44.     clr.b    $BFEA01     ; reset CIA-A event counter
  45.     clr.b    $BFE901
  46.     clr.b    $BFE801
  47.  
  48. waitblit:
  49.     move.w    DMACONR,d7
  50.     btst    #14,d7        ; wait for blitter DMA to stop
  51.     bne.s    waitblit
  52.  
  53.     move.w    #$3FFF,INTENA    ; disable all possible interrupt sources
  54.     move.w    #$3FFF,INTREQ    ; clear all pending interrupts
  55.     move.w    #$01FF,DMACON    ; disable DMA (bitplane, copper, blitter)
  56.  
  57.     move.w    #0,BPLCON1    ; scroll value=0. Messed up by rolling titles?
  58.  
  59.     movea.l $4,a6
  60.     move.w    AttnFlags(a6),d4
  61.  
  62.     btst    #$0,d4        ; branch if <'010 or more
  63.     beq.s    go_on2
  64.  
  65.     btst    #3,d4
  66.     beq.s    go_on1
  67.  
  68.     moveq    #0,d1        ; MMU off
  69.     dc.w    $4E7B,$1003    ; movec d1,TCR
  70.  
  71. go_on1:
  72.     moveq    #0,d0
  73.     dc.w    $4E7B,$0801    ; movec a6,VBR
  74.  
  75.     bsr    CLRALL        ; clear instruction & data caches
  76.  
  77.     moveq    #0,d0        ; new cache bits
  78.     move.l    #CACRF_EnableI|CACRF_EnableD,d1 ; mask
  79.     bsr    CTRLCACHE
  80.  
  81. go_on2:
  82.     movem.l $4(a7),a0-a4
  83.     movem.l $18(a7),d0-d4
  84.  
  85.     lea    _subtoclear-_theworks(a0),a7
  86.  
  87.     lea    _theworks(pc),a6
  88.     move.l    #(_dummy-_theworks)>>1-1,d6
  89.     move.l    a0,d7
  90. mvlup:
  91.     move.w    (a6)+,(a0)+
  92.     dbra    d6,mvlup
  93.  
  94.     move.l    d7,a0
  95.     jmp    (a0)
  96.  
  97. ; -------------------------------------------------------------
  98. ;  clear data and instruction caches
  99.  
  100. CLRALL:
  101.     movem.l d0-d1/d4,-(a7)
  102.  
  103.     move.l    #$808,d1
  104.     bra.s    L0000C3E
  105.  
  106. ; -------------------------------------------------------------
  107. ;  clear data caches
  108.  
  109. CLRDATA:
  110.     movem.l d0-d1/d4,-(a7)
  111.  
  112.     moveq    #$8,d1
  113.     rol.l    #8,d1
  114.  
  115. ; -------------------------------------------------------------
  116. ;  clear cache(s). d1=$800 - clear data cache
  117. ;           d1=$808 - clear data and instruction caches
  118.  
  119. ;          and on 68040 - update memory from caches
  120.  
  121. L0000C3E:
  122.     ori.w    #$0700,sr    ; interrupts off
  123.  
  124.     movea.l $4,a6
  125.     move.w    AttnFlags(a6),d4
  126.  
  127.     btst    #$1,d4        ; branch if '020 or more
  128.     bne.s    L0000C48
  129.  
  130.     bra.s    CLRCACHEX    ; ...otherwise exit
  131.  
  132. L0000C48:
  133.     btst    #$3,d4
  134.     bne.s    L0000C68    ; '040 ?
  135.  
  136.     and.l    #$808,d1
  137.     ori    #$700,sr
  138.     dc.w    $4E7A,$0002    ; movec cacr,d0
  139.     or.l    d1,d0
  140.     dc.w    $4E7B,$0002    ; movec d0,cacr
  141.  
  142.     ifd    ShoCach
  143.     move.l    d7,-(a7)
  144.     move.w    #$8000,d7
  145. WAITRED:
  146.     move.w    #$0F00,$DFF180
  147.     move.w    #0,$DFF180
  148.     dbra    d7,WAITRED
  149.     move.l    (a7)+,d7
  150.     endif
  151.  
  152.     bra.s    CLRCACHEX
  153.  
  154. L0000C68:
  155.     btst    #$3,d1
  156.     bne.s    L0000C74
  157.  
  158.     dc.w    $F478        ; CPUSHA dc ('040 only)
  159.                 ; update memory from cache
  160.     bra.s    L0000C76
  161.  
  162. L0000C74:
  163.     dc.w    $F4F8        ; CPUSHA ic/dc ('040 only)
  164.                 ; update memory from caches
  165. L0000C76:
  166.  
  167. CLRCACHEX:
  168.     movem.l (a7)+,d0-d1/d4
  169.     tst.l    d0
  170.  
  171.     rts
  172.  
  173. ; -------------------------------------------------------------
  174. ;  set bits in cacr d0=bits to set d1=bits to clear/alter
  175.  
  176. CTRLCACHE:
  177. L0000C8E:
  178.     movem.l d2-d4,-(a7)
  179.  
  180.     moveq    #$0,d3
  181.  
  182.     movea.l $4,a6
  183.     move.w    AttnFlags(a6),d4
  184.  
  185.     btst    #$1,d4        ; exit if not at least '020
  186.     beq.s    L0000CAE
  187.  
  188.     and.l    d1,d0
  189.     or.w    #$808,d0    ; signal clear data & instr.
  190.     not.l    d1
  191.  
  192. L0000CB6:
  193.     ori    #$700,sr
  194.     dc.w    $4E7A,$2002    ; movec cacr,d2
  195.     btst    #$3,d4
  196.     beq.s    L0000CD0    ; skip if not '040
  197.  
  198.     swap    d2        ; '040 code
  199.     ror.w    #8,d2
  200.     rol.l    #1,d2
  201.     move.l    d2,d3
  202.     rol.l    #4,d3
  203.     or.l    d3,d2
  204.  
  205. L0000CD0:
  206.     move.l    d2,d3        ; cache register to d3
  207.     and.l    d1,d2        ; mask off changed bits
  208.     or.l    d0,d2        ; or in set bits
  209.     btst    #$3,d4
  210.     beq.s    L0000CEC    ; skip if not '040
  211.  
  212.     ror.l    #1,d2        ; '040 code
  213.     rol.w    #8,d2
  214.     swap    d2
  215.     and.l    #$80008000,d2
  216.     nop
  217.     dc.w    $F4F8        ; CPUSHA ic/dc ('040 only)
  218.                 ; update memory from caches
  219.  
  220. L0000CEC:
  221.     nop
  222.     dc.w    $4E7B,$2002    ; movec d2,cacr
  223.     nop
  224.  
  225. L0000CAE:
  226.     move.l    d3,d0
  227.  
  228.     movem.l (a7)+,d2-d4
  229.     rts
  230.  
  231. ; --------------------------------------------------------------
  232. _theworks:
  233.     move.w    #MAGENTA,COLOR00
  234.  
  235.     move.l    d0,d5
  236.  
  237.     sub.l    a0,a0
  238.     lsr.l    #1,d0
  239.     subq.l    #1,d0
  240.  
  241. qmvlup:
  242.     move.w    (a4),(a0)+    ; move QDOS code
  243.     clr.w    (a4)+
  244.     dbra    d0,qmvlup
  245.  
  246.     cmpa.l    a2,a3        ; relocate QDOS
  247.     beq.s    newbit
  248.  
  249.     move.l    d5,a5
  250.     move.w    -(a5),d0
  251.     bra.s    rloctst
  252.  
  253. rloclup:
  254.     moveq    #0,d6
  255.     move.w    -(a5),d6
  256.     move.l    d6,a0
  257.     move.l    (a0),d6
  258.     add.l    a2,d6
  259.     sub.l    #$600,d6
  260.     move.l    d6,(a0)
  261.  
  262. rloctst:
  263.     dbra    d0,rloclup
  264.  
  265.     move.l    a2,a5        ; move QDOS
  266.     move.l    d5,d0
  267.     movea.l #$600,a0
  268.     sub.l    a0,d0
  269.     lsr.l    #1,d0
  270.     subq.l    #1,d0
  271.  
  272. zmvlup:
  273.     move.w    (a0),(a5)+
  274.     clr.w    (a0)+
  275.     dbra    d0,zmvlup
  276.  
  277. newbit:
  278.     lea    $1C000,a0
  279.     move.l    d2,d0
  280.     lsr.l    #1,d0
  281.     subq.l    #1,d0
  282.  
  283. xmvlup:
  284.     move.w    (a4),(a0)+    ; move MAIN code
  285.     clr.w    (a4)+
  286.     dbra    d0,xmvlup
  287.  
  288.     move.l    a4,a5
  289.  
  290.     tst.l    d1
  291.     beq.s    clrmem
  292.  
  293.     cmp.l    a5,a3    ; check which direction we should
  294.     blt.s    rmvdn    ; move roms and act accordingly.
  295.  
  296. rmvup:
  297.     add.l    d1,a5    ; after last word in ROM code
  298.     add.l    d1,a3    ; after last word of destination area
  299.     lsr.l    #1,d1
  300.  
  301.     bra.s    rmvuptst
  302.  
  303. rmvuphilup:
  304.     swap    d1
  305.  
  306. rmvuplolup:
  307.     move.w    -(a5),-(a3)   ; move the ROM code
  308.     clr.w    2(a5)
  309.  
  310. rmvuptst:
  311.     dbra    d1,rmvuplolup
  312.     swap    d1
  313.     dbra    d1,rmvuphilup
  314.     bra.s    clrmem
  315.  
  316. rmvdn:
  317.     lsr.l    #1,d1
  318.  
  319.     bra.s    rmvdntst
  320.  
  321. rmvdnhilup:
  322.     swap    d1
  323.  
  324. rmvdnlolup:
  325.     move.w    (a5),(a3)+   ; move the ROM code
  326.     clr.w    (a5)+
  327.  
  328. rmvdntst:
  329.     dbra    d1,rmvdnlolup
  330.     swap    d1
  331.     dbra    d1,rmvdnhilup
  332.  
  333. clrmem:
  334.     moveq    #0,d0
  335.     bra.s    getrange
  336.  
  337. clrlup:
  338.     move.l    d0,(a3)+
  339.  
  340. clrtst:
  341.     cmp.l    a5,a3
  342.     blt.s    clrlup
  343.  
  344. getrange:
  345.     move.l    (a7)+,a3
  346.     move.l    (a7)+,a5
  347.     cmp.l    d0,a5
  348.     bne.s    clrtst
  349.  
  350. doql:
  351.     move.l    $4,a0    ; get initial PC
  352.  
  353.     move.l    d3,a7    ; get initial SSP
  354.     move.l    a7,$0    ; and store it
  355.  
  356.     and.l    #-$8000,d3    ; calculate address of system variables
  357.     move.l    d3,a6
  358.  
  359.     move.w    #$D254,(a6)    ; set QDOS id
  360.     move.l    a1,$04(a6)    ; store lomem
  361.     move.l    a2,$20(a6)    ; store himem
  362.  
  363.     move.l    d4,$18000    ; store date
  364.  
  365.     move.w    #GREEN,COLOR00
  366.  
  367.     jmp   (a0)    ; start QDOS
  368.  
  369.     rts
  370.  
  371. ;   this area is filled by the c code with the address ranges
  372. ;   that it is necessary to clear (a maximum of 8, zero terminated).
  373.  
  374. _subtoclear:
  375.     dcb.l    18,0
  376.  
  377. _dummy:
  378.     xdef    _sub
  379.     xdef    _subtoclear
  380.     xdef    _dummy
  381.     xdef    _theworks
  382.  
  383.     end
  384.